$(function(){
    $(".btn-primary").click(function(){

            var goods_title = $('.goods_title').val();
            var goods_brand = $('.goods_brand').val();
            var goods_a_type = $('.goods_a_type').val();
            var goods_b_type = $('.goods_b_type').val();
            var goods_price = $('.goods_price').val();
            var goods_repertory = $('.goods_repertory').val();
            var goods_image = $('.goods_image').val();
            if(goods_title==''){
                errorTips('btn-primary',$(".goods_title"),"请输入商品名称");
                return ;
            }
            if(goods_brand==''){
                errorTips('btn-primary',$(".goods_brand"),"请输入商品品牌");
                return ;
            }
            if(goods_a_type==''){
                errorTips('btn-primary',$(".goods_a_type"),"请选择商品分类");
                return ;
            }
            if(goods_b_type==''){
                errorTips('btn-primary',$(".goods_b_type"),"请选择商品分类");
                return ;
            }
            if(goods_price==''){
                errorTips('btn-primary',$(".goods_price"),"请输入商品价格");
                return ;
            }
            if(goods_repertory==''){
                errorTips('btn-primary',$(".goods_repertory"),"请输入商品库存");
                return ;
            }

            if(goods_title==''){
                errorTips('btn-primary',$(".goods_title"),"请输入登陆账号");
                return ;
            }
            /*
             *表单提交
             */
                var uri = $("#g_add").attr("action");
                var data = $("form[id=g_add]").serialize();
                ajaxPost(uri, $(".btn-primary"), data, function(r){
                    $(".btn-primary").removeAttr("disabled");
                    location.href = r.url;
                });
            });
            /*
            商品二级分类
             */
            $('.goods_a_type').click(function(){
                var typeName = $(this).val();
                $.ajax({
                    type:'POST',
                    dataType:"json",
                    url:"/admin/Goods/AjaxType",
                    data:{id:typeName},
                    success:function(data){
                        $(".goods_b_type").empty();
                        var count = data.length;
                        var i = 0;
                        var b="";
                           for(i=0;i<count;i++){
                               b+="<option  value='"+data[i].goods_type_id+"'>"+data[i].goods_type_name+"</option>";
                           }
                        $(".goods_b_type").append(b);

                    },
                    error:function(){
                        layer.msg('异常');
                    }
                });
              });

});